package main

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"main.go/models"
)

func main() {
	dsn := "root:123456@tcp(139.224.212.247:3306)/gin_chat?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}

	// 迁移 schema
	db.AutoMigrate(&models.UserBasic{})

	// Create
	db.Create(&models.UserBasic{Name: "张三"})

	// Read
	user := &models.UserBasic{}
	db.First(user, 1) // 根据整型主键查找

	// Update - 将 product 的 price 更新为 200
	db.Model(user).Update("PassWord", 1234)

}
